package com.cgy.repository;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.cgy.entity.Student;

//继承jpa接口  jpaRepository：实现基本的增删改查。 JpaSpecificationExecutor：实现复杂动态查询
public interface studentRepository extends JpaRepository<Student, Integer>,JpaSpecificationExecutor<Student>{
		
	//原生sql  ?1:第一个参数  
	@Query(value = "delete from Student WHERE sid=?1")  
    @Modifying  //通知jpa这是一个update或者delete操作
    @Transactional//事务  
	Integer deleteStudentByID(Integer sid);
	//验证卡号是否存在
	@Query(value = "select *  from Student WHERE s_card_id=?1" ,nativeQuery = true)  
	List<Student> findLikecard(Integer scardid);
	//根据卡号修改学生状态
	@Query(value = "UPDATE Student SET status =1 WHERE s_card_id =?1" ,nativeQuery = true)  
	Integer upstudentstatus(Integer scardid);
}
